import sys

from java.util import Locale
from java.lang import String
from java.lang  import System
from java.lang  import Boolean
from java.io import File

from java.awt import Color
from java.awt  import Font

from jhplot import HPlotJa
from jhplot import P1D
from jhplot.jadraw import JaAxes
from jhplot.jadraw import JaText
from jhplot.jadraw import JaKey

from jscinttools.utilities.jheputilities import HPlotJaUtil
from jscinttools.utilities.jheputilities import FigureParametersJHep

class TestImplInterface(FigureParametersJHep):
	def __init__(self, show, write):
	
		Locale.setDefault(Locale.ENGLISH)
		showFigures = True
		writeFigures = False
		
		print show
		if show == "true" or show == "True":
			showFigures = True
		elif show == "false" or show == "False":
			showFigures = False
			
		if write == "true" or write == "True":
			writeFigures = True
		elif write == "false" or write == "False":
			writeFigures = False
					
		print showFigures
		print writeFigures
		
		""" Define the Path and files names """
		rangeVal = [2.5, 6]
		rangeZoom = [2.95, 2.98]
		
		
		indPhotFile = "/home/marc-antoine/Documents/BGO/QFin/ScintEventBGO/indPhot"
		
		outPath = "/home/marc-antoine/Documents/Test"
		outName = "SingleEvent300K"
		
		
		""" 
		###############################################################
		# Create the P1D
		###############################################################
		"""
		indivPhot = P1D("Photons", indPhotFile, style="p", color=self.colors[1], symbol=6, symbolSize=8, errAll=False)
		
		
		"""
		###############################################################
		# Plotting Part
		###############################################################
		"""
		indivPhotKey = JaKey(indivPhot.symbol, indivPhot.title, 0.165, 0.775, "NDC", color=indivPhot.color, keyColor=indivPhot.color, penWidth=2, font=self.legendFont)
		
		
		
		""" Create the Plotter """
		mainPlotter = HPlotJa("Single Event", 600, 600, 2, 1, True)
		mainPlotter.setGTitle("Scintillation Event in BGO with ^{22}Na at 300 K", self.titleFont)
		mainPlotter.setAntiAlias(False)
		if showFigures:
			mainPlotter.visible(True)
		else:
			mainPlotter.visible(False)
		mainPlotter.cd(1,1)
		mainPlotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
		mainPlotter.setRange(rangeVal[0], rangeVal[1], -0.85, 0.1)
		mainPlotter.setLogScale(0, False)
		mainPlotter.setLogScale(1, False)
		mainPlotter.setTicFont(self.ticFont)
		mainPlotter.setShowStatBox(False)
		mainPlotter.showKey(False)
		mainPlotter.setNameX("Time (&micro;s)")
		mainPlotter.setNameY("Amplitude (V)")
		
		mainPlotter.cd(2,1)
		mainPlotter.setPad(2, 1, 0.465, 0.455, 0.35, 0.35)
		mainPlotter.setRange(rangeZoom[0], rangeZoom[1], -0.5, 0.1)
		mainPlotter.setLogScale(0, False)
		mainPlotter.setLogScale(1, False)
		mainPlotter.setTicFont(self.ticFont)
		mainPlotter.setShowStatBox(False)
		mainPlotter.showKey(False)
		mainPlotter.setNameX("")
		mainPlotter.setNameY("")
		
		""" Plots all the JHep objects """
		mainPlotter.cd(1,1)
		mainPlotter.draw(indivPhot)
		mainPlotter.draw(indivPhotKey)
		
		mainPlotter.cd(2,1)
		mainPlotter.draw(indivPhot)
		
		
		""" Modifies the JaAxes and the axes labels """
		labX_11 = mainPlotter.getLabelX()[0][0]
		labX_11.setFont(self.axisLabelFont)
		HPlotJaUtil.setLabelLocationAtCenter(0, labX_11, mainPlotter)
		labY_11 = mainPlotter.getLabelY()[0][0]
		labY_11.setFont(self.axisLabelFont)
		HPlotJaUtil.setLabelLocationAtCenter(1, labY_11, mainPlotter, -0.01)
		
		mainPlotter.cd(1,1)
		theAxes = mainPlotter.getPad()
		theAxes.setLabelSpace(0, 0.0)
		theAxes.setLabelSpace(1, 0.0)
		
		mainPlotter.cd(2,1)
		theAxes = mainPlotter.getPad()
		theAxes.setLabelSpace(0, 0.0)
		theAxes.setLabelSpace(1, 0.0)
		
		mainPlotter.update()
		
		""" Saves or not the plot """
		if writeFigures:
			for i in range(len(self.figType)):
				outFileName = outName + self.figType[i]
				mainPlotter.export(outPath + File.separator + outFileName)
				print("Writting File : " + outPath + File.separator + outFileName)
				
		mainPlotter.update()

def main(argv):
	#try:
	#	opts, args = getopt.getopt(argv, "hg:d", ["help", "grammar="])
	#except getopt.GetoptError:
	#	usage()
	#	sys.exit(2)
	for arg in sys.argv:
		print arg
	t = TestImplInterface(argv[1], argv[2])	
	
	
if __name__ == "__main__":
	main(sys.argv)
	#t = TestImplInterface(sys.argv[1])	
	print("That's all folks !")

